﻿using SuperMoney.Datas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;

namespace SuperMoney
{
	/// <summary>
	/// 
	/// </summary>
	public class CheckInService
	{
		/// <summary>
		/// 
		/// </summary>
		public static readonly CheckInService Instance = new CheckInService();

		/// <summary>
		/// 
		/// </summary>
		/// <param name="deviceId"></param>
		public void CheckIn(string deviceId)
		{
			// 
			using (TransactionScope tx = new TransactionScope())
			{
				var checkIn = CheckInDbService.Instance.Create(deviceId, 1);
				string name = checkIn.CheckDay.ToString("yyyy-MM-dd") + "签到";
				IntegralTradeService.Instance.Create(deviceId, IntegralTradeCategory.Income, checkIn.Integral, name, IntegralTradeAssociation.CheckIn, checkIn.Id);
				tx.Complete();
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="deviceId"></param>
		/// <returns></returns>
		public bool Exists(string deviceId)
		{
			//
			return CheckInDbService.Instance.Exists(deviceId, DateTime.Today);
		}
	}
}
